<template>
  <div class="index">
    <!-- 顶部 -->
    <div class="top"><Admin></Admin></div>
    <!-- bottom -->
    <div class="bottom">
      <div class="left"><SideNav></SideNav></div>
      <div class="right">
        <div class="content">
          <el-scrollbar style="height: 100%;">
            <!-- 当前位置 -->
            <div class="current_position">
              <p class="breadcrumb">当前位置 :</p>
              <el-breadcrumb separator="/">
                <el-breadcrumb-item class="up">生活服务</el-breadcrumb-item>
                <el-breadcrumb-item>退款订单</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <!-- 列表 -->
            <div class="userlist">
              <div class="status_box">
                <div class="status">
                  <el-select v-model="value" placeholder="订单号" @change="findList()">
                    <el-option v-for="(item,index) in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
                  </el-select>
                </div>
                <div class="input" @keyup.enter="findList()">
                  <el-input v-model="input" clearable></el-input>
                </div>
                <p class="title">商品名称</p>
                <div class="input" @keyup.enter="findList()">
                  <el-input v-model="name" clearable></el-input>
                </div>
                <p class="title">退款时间</p>
                <el-date-picker  v-model="value2"  type="daterange"  range-separator="至"  start-placeholder="开始日期"  end-placeholder="结束日期"></el-date-picker>
                <div class="search"><el-button @click="findList()">搜索</el-button></div>
              </div>
              <div class="table">
                <el-table ref="multipleTable" :data="tableData" border tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
                  <el-table-column type="selection" fixed="left" width="50"></el-table-column>
                  <el-table-column prop="createTime" label="申请时间" :formatter="dateForma"></el-table-column>
                  <el-table-column prop="tradeId" label="订单号"></el-table-column>
                  <el-table-column prop="mouldName" label="商品信息"></el-table-column>
                  <el-table-column prop="customerNickName" label="买家"></el-table-column>
                  <el-table-column prop="customerPhoneNum" label="收件人/电话"></el-table-column>
                  <el-table-column prop="disbursements" label="实付款"></el-table-column>
                  <el-table-column prop="reason" label="类型"></el-table-column>
                  <el-table-column prop="disbursements" label="退款金额"></el-table-column>
                  <el-table-column prop="remark" label="备注"></el-table-column>
                  <el-table-column prop="id" label="状态">
                    <template slot-scope="scope">
                      <span v-if="scope.row.status==1" class="putaway">退款成功</span>
                      <span v-if="scope.row.status==2" class="soldout">拒绝退款</span>
                      <span v-if="scope.row.status==3" class="soldout">申请中</span>
                      <span v-if="scope.row.status==4" class="soldout">退款失败</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" fixed="right"  width="100">
                    <template slot-scope="scope">
                      <el-button @click="sure(scope.row)" type="text" size="small">同意</el-button>
                      <el-button @click="notSure(scope.row)" type="text" size="small">拒绝</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage"
                  :page-sizes="[10,20,30,40,50]"
                  :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
                </el-pagination>
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  let moment = require("moment")
  import Admin from '@/components/Admin.vue'
  import SideNav from '@/components/SideNav.vue'

  export default {
    name: 'Refund',
    components:{
      Admin,
      SideNav
    },
    data () {
      return {
        page: 1,//页码
        pageSize: 10,//每页条数
        total: 0,/* 总的条数 */
        currentPage: 0,/* 前往第几页 */
        options: [{//账号状态
          value: '1',
          label: '订单号',
        },{
          value: '2',
          label: '收件人电话',
        }],
        value: null,//账号状态
        input: null,// 搜索输入框
        name:'',//商品名称
        value2:'',//开始结束时间
        tableData: [],// 表格
        multipleSelection: [], // 选择后的列表
      }
    },
    mounted() {
      this.findList();
    },
    methods: {
      // 时间格式过滤
      dateForma(row,column){
        var date = row[column.property];
        if(date == undefined){
          return ''
        }
        return moment(date).format("YYYY-MM-DD HH:mm:ss")
      },
      // 获取所有退款订单
      findList(){
        this.$axios.post(this.baseURL1+'admin/requestRefund/list',{
          "page":this.page,
          "size":this.pageSize,
          "requestSource":"PC"
        }).then((res)=>{
          console.log(res,"退款订单");
          if(res.data.code==1){
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          }
        }).catch((err)=>{
          console.log('request fail', err);
        })
      },
      // 表格的全选
      handleSelectionChange(val) {
        console.log(val);
        this.multipleSelection = val;
      },
      // 同意退款
      sure(row) {
        this.$confirm('确认同意退款?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post(this.baseURL1+'admin/requestRefund/agree',{
            "id": row.id,
            "requestSource":"PC",
          }).then((res)=>{
            if(res.data.code==0){
              this.$message({
                type: 'success',
                message: '退款成功'
              });
              setTimeout(()=>{
                this.findList();
              },1000)
            }else{
              this.$message({
                type: 'error',
                message: res.data.msg
              });
            }
          }).catch((err)=>{
            console.log('request fail', err);
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      },
      //拒绝退款
      notSure(row) {
        this.$confirm('确认拒绝退款?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post(this.baseURL1+'admin/requestRefund/refuse',{
            "id": row.id,
            "requestSource":"PC",
          }).then((res)=>{
            if(res.data.code==0){
              this.$message({
                type: 'success',
                message: '已拒绝退款'
              });
              setTimeout(()=>{
                this.findList();
              },1000)
            }else{
              this.$message({
                type: 'error',
                message: res.data.msg
              });
            }
          }).catch((err)=>{
            console.log('request fail', err);
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      },
      // 选择的每页条数
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.findList();
      },
      // 当前页面
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.page = val;
        this.findList();
      },
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  @import '@/assets/css/index.scss'; //这个分号一定要写，要不会报错
  @import '@/assets/css/user.scss'; //这个分号一定要写，要不会报错
  .title{
    width: 80px;
    text-align: right;
    line-height: 45px;
  }
  >>> .el-date-editor.el-input{
    width: 200px;
  }
  >>> .el-input__inner{
    height: 35px;
    line-height: 35px;
    padding: 0 5px;
    margin: 7px 5px;
  }
</style>
